﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Jewelnoid
{
    class FloatingScoreManager
    {
        public SpriteFont spriteFont;
        public List<FloatingScore> floatingScoreList;

        public FloatingScoreManager(SpriteFont spriteFont)
        {
            this.spriteFont = spriteFont;

            floatingScoreList = new List<FloatingScore>();
        }

        public void create(String text, Vector2 position)
        {
            floatingScoreList.Add(new FloatingScore(this.spriteFont, text, position));
        }

        public void update()
        {
            removeUnusedScoresFromList();

            foreach (FloatingScore score in floatingScoreList)
            {
                score.update();
            }
        }

        public void draw(SpriteBatch spriteBatch)
        {
            foreach (FloatingScore score in floatingScoreList)
            {
                score.draw(spriteBatch);
            }
        }

        public void removeUnusedScoresFromList()
        {
            List<FloatingScore> toRemoveList = new List<FloatingScore>();

            foreach (FloatingScore score in floatingScoreList)
            {
                if (score.alpha == 0)
                {
                    toRemoveList.Add(score);
                }
            }

            foreach (FloatingScore scoreToRemove in toRemoveList)
            {
                floatingScoreList.Remove(scoreToRemove);
            }
        }
    }
}
